/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgLevelDropLibControl
    {
        private readonly Dictionary<int, CfgLevelDropLibControl> _dataMap;
        private readonly List<CfgLevelDropLibControl> _dataList;

        /// <summary>
        /// 通过DropLibId字段查询id
        /// </summary>
        public IReadOnlyDictionary<int, int> dropLibIdMap { get; private set; }

        public TbCfgLevelDropLibControl(ByteBuf _buf)
        {
            //first read common data
            _TbCommonLevelDropLibControl _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonLevelDropLibControl(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgLevelDropLibControl>(size * 3 / 2);
            _dataList = new List<CfgLevelDropLibControl>(size);

            for (int i = 0; i < size; i++)
            {
                CfgLevelDropLibControl _v;
                _v = CfgLevelDropLibControl.DeserializeCfgLevelDropLibControl(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 
            { int __n0 = _buf.ReadSize(); var __f0 = new Dictionary<int, int> (__n0 * 3 / 2); dropLibIdMap = __f0 ; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ) { int __k0; __k0 = _buf.ReadInt(); int __v0; __v0 = _buf.ReadInt(); __f0.Add(__k0, __v0); } }

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgLevelDropLibControl> DataMap => _dataMap;
        public IReadOnlyList<CfgLevelDropLibControl> DataList => _dataList;

        public CfgLevelDropLibControl Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgLevelDropLibControl] config not found,id:" + key.ToString());

            return null;
        }

        public CfgLevelDropLibControl GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "leveldroplibcontrol";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgLevelDropLibControl LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgLevelDropLibControl(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgLevelDropLibControl
    {
        private CfgLevelDropLibControl(ByteBuf _buf, _TbCommonLevelDropLibControl _commonData)
        {
            Id = _buf.ReadInt();
            DropLibId = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; ActivityStartTime = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; ActivityEndTime = _commonData._field1[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; ConditionId = _commonData._field2[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; ControlType = _commonData._field3[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; ExDropLibId = _commonData._field4[dataIndex]; }

            PostInit();
        }

        internal static CfgLevelDropLibControl DeserializeCfgLevelDropLibControl(ByteBuf _buf, _TbCommonLevelDropLibControl _commonData)
        {
            return new CfgLevelDropLibControl(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 掉落目标
        /// </summary>
        public int DropLibId { get; private set; }
        /// <summary>
        /// 开始时间
        /// </summary>
        public string ActivityStartTime { get; private set; }
        /// <summary>
        /// 结束时间
        /// </summary>
        public string ActivityEndTime { get; private set; }
        /// <summary>
        /// 控制条件
        /// </summary>
        public IReadOnlyList<int> ConditionId { get; private set; }
        /// <summary>
        /// 控制类型：1新增，2替换
        /// </summary>
        public IReadOnlyList<int> ControlType { get; private set; }
        /// <summary>
        /// 额外id
        /// </summary>
        public IReadOnlyList<int> ExDropLibId { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonLevelDropLibControl
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<string> _field1 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field2 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field3 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field4 { get; private set; }
        internal _TbCommonLevelDropLibControl(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
